#######################################################
#    Build Common Util
#######################################################
import os

Import('connectivity_env')

ca_transport = connectivity_env.get('TARGET_TRANSPORT')
target_os = connectivity_env.get('TARGET_OS')
with_cloud = connectivity_env.get('WITH_CLOUD')
with_tcp = connectivity_env.get('WITH_TCP')

######################################################################
# Source files to build common for platforms
######################################################################

src_files = [File('src/cautilinterface.c'),]

if target_os == 'android':
    if 'BLE' in ca_transport or 'ALL' in ca_transport:
        bt_srcdir = 'src/camanager/bt_le_manager/android/'
        src_files.extend([File(src) for src in (
            bt_srcdir + 'caleconnectionmanager.c',
            bt_srcdir + 'caleautoconnector.c',
            bt_srcdir + 'camanagerleutil.c',
            bt_srcdir + 'camanagerdevice.c',
        )])
        connectivity_env.AppendUnique(CPPPATH=['../src/bt_le_adapter/android'])

    if 'BT' in ca_transport or 'ALL' in ca_transport:
        bt_srcdir = 'src/btpairing/android/'
        src_files.extend([File(src) for src in (
            bt_srcdir + 'cabtpairing.c',
        )])

if target_os == 'tizen':
    if 'BLE' in ca_transport or 'ALL' in ca_transport:
        bt_srcdir = 'src/camanager/bt_le_manager/tizen/'
        src_files.extend([File(src) for src in (
           bt_srcdir + 'caleconnectionmanager.c',
        )])
        connectivity_env.AppendUnique(CPPPATH=['../src/bt_le_adapter/tizen'])

if with_cloud and with_tcp:
    ca_srcdir = 'src/camanager/'
    src_files.extend([File(src) for src in (
        ca_srcdir + 'caconnectionmanager.c',
        ca_srcdir + 'camanagerutil.c',
        ca_srcdir + 'camessagearbiter.c',
        ca_srcdir + 'capolicymanager.c',
    )])

connectivity_env.AppendUnique(CA_SRC=src_files)
